package com.tml.servlet;

import com.tml.service.ILoginService;
import com.tml.service.impl.LoginService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name=req.getParameter("userName");
        System.out.println(name);
        String pwd=req.getParameter("userPwd");
        System.out.println(pwd);

        //LoginService loginService=new LoginService();
        ILoginService loginService = new LoginService();
        boolean islogin = loginService.login(name,pwd);
        if (islogin) {
            HttpSession session =req.getSession();
            session.setAttribute("userName",name);
            resp.sendRedirect("home.do");
        }else{
            resp.sendRedirect("login.jsp?error=1");
        }



    }
}
